﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Controls;

namespace Albatross.WPF.Common {
	public interface IWorkspaceConstruct<T> : IWorkspaceConstruct where T:IWorkspaceViewModel {
		new T Constructed { get; }
		new T Build();
	}

	public interface IWorkspaceConstruct{
		Type ViewModelType { get; }
		Type ViewType { get; }
		object[] Args { get; set; }
		IWorkspaceViewModel Constructed { get; }
		string Region { get; set; }
		object WorkspaceID { get; set; }
		bool KeepAlive { get; set; }
		IWorkspaceViewModel Build();
		UserControl GetView();
	}

	public static class WorkspaceConstructExt {
		public static IWorkspaceConstruct SetWorkspaceID(this IWorkspaceConstruct construct, object workspaceID) {
			construct.WorkspaceID = workspaceID;
			return construct;
		}
		public static IWorkspaceConstruct SetArgs(this IWorkspaceConstruct construct, params object[] args) {
			construct.Args = args;
			return construct;
		}
		public static IWorkspaceConstruct SetAlive(this IWorkspaceConstruct construct, bool keepAlive) {
			construct.KeepAlive = keepAlive;
			return construct;
		}
		public static IWorkspaceConstruct SetRegion(this IWorkspaceConstruct construct, string region) {
			construct.Region = region;
			return construct;
		}
		public static bool IsEmpty(this IWorkspaceConstruct construct) {
			return construct.ViewModelType == null;
		}
		public static IWorkspaceConstruct CreateByObject(IWorkspaceViewModel vm) {
			return new WorkspaceConstruct(vm);
		}
		public static IWorkspaceConstruct EmptyConstruct(string region) {
			return new WorkspaceConstruct(region);
		}
	}
}
